<template>
  <!-- 基础平台 -->
  <div class="basis">
    <div class="header">
      <p class="title">基础平台版块</p>
    </div>
    <div class="display">
      <div class="item">
        <span class="icon icon1"></span>
        <div class="data">
          <p class="val">
            <count-to :startVal="0" :endVal="pv" :duration="1000"></count-to>
          </p>
          <p class="key">平台累计PV量(人次)</p>
        </div>
      </div>
      <span class="line"></span>
      <div class="item">
        <span class="icon icon2"></span>
        <div class="data">
          <p class="val">
            <count-to
              :startVal="0"
              :endVal="compCount"
              :duration="1000"
            ></count-to>
          </p>
          <p class="key">认证企业数(家)</p>
        </div>
      </div>
      <span class="line"></span>
      <div class="item">
        <span class="icon icon3"></span>
        <div class="data">
          <p class="val">
            <count-to
              :startVal="0"
              :endVal="userCount"
              :duration="1000"
            ></count-to
            ><span class="unit"></span>
          </p>
          <p class="key">注册用户数(个)</p>
        </div>
      </div>
      <span class="line"></span>
      <div class="item">
        <span class="icon icon4"></span>
        <div class="data">
          <p class="val">
            <count-to
              class="item-number"
              :startVal="0"
              :endVal="studentCount"
              :duration="1000"
            ></count-to>
          </p>
          <p class="key">小程序用户数(个)</p>
        </div>
      </div>
    </div>
    <div class="chart-wrap">
      <Echart id="basis-chart" :options="option" height="232px" width="100%" />
    </div>
  </div>
</template>

<script setup>
import { onMounted, reactive, ref } from "vue";
import Echart from "@/components/echart/index.vue";
import CountTo from "@/components/vueCountTo/vue-countTo.vue";
import { ajax } from "@/store/service";
import { dataGroup } from "@/utils";
import opt from "./basisPlatformOpt";

const pv = ref(0);
const compCount = ref(0);
const userCount = ref(0);
const studentCount = ref(0);

const option = reactive({ ...opt });

const init = async() => {
  const [res]=await ajax.basePlatform()
  pv.value=res.pv
  compCount.value=res.compCount
  userCount.value=res.userCount
  studentCount.value=res.studentCount
  const chart = dataGroup(res.chart);
  option.xAxis[0].data = chart.x;
  option.series[0].data = chart.y;
  
};

onMounted(() => {
  init();
});
</script>
<style scoped lang='scss'>
.basis {
  width: 1114px;
  height: 408px;
  .header {
    width: 100%;
    height: 79px;
    background: url("@/assets/longscreen2/title-long.png");
    box-sizing: border-box;
    padding-top: 14px;
    margin-bottom: 16px;
    .title {
      margin-left: 68px;
      font-size: 22px;
      font-family: JLinXin;
      font-weight: 600;
      line-height: 22px;
      background: #fffde8 linear-gradient(180deg, #e8feff 40%, #00a9ff 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      font-weight: bold;
    }
  }
  .display {
    padding: 0 40px;
    display: flex;
    justify-content: space-between;
    margin-bottom: 19px;
    .item {
      display: flex;
      align-items: center;
      .icon {
        width: 50px;
        height: 50px;
        display: block;
      }
      .icon1 {
        background: url("@/assets/longscreen2/icon_累计开展培训.svg");
      }
      .icon2 {
        background: url("@/assets/longscreen2/icon_认证企业数.svg");
        background-size: 100% 100%;
        background-position: center center;
      }
      .icon3 {
        background: url("@/assets/longscreen2/icon_注册用户数.svg");
      }
      .icon4 {
        background: url("@/assets/longscreen2/icon_小程序用户数.svg");
      }
      .data {
        margin-left: 12px;
        .val {
          font-size: 26px;
          font-family: D-DIN-PRO-ExtraBold, D-DIN-PRO;
          font-weight: 800;
          color: #ffffff;
          line-height: 30px;
          letter-spacing: 1px;
          margin-bottom: 8px;
          .unit {
            font-size: 18px;
            font-family: SourceHanSansCN-Medium, SourceHanSansCN;
            font-weight: 500;
            color: #ffffff;
            line-height: 27px;
            opacity: 0.36;
            margin-left: 3px;
          }
        }
        .key {
          font-size: 18px;
          font-family: SourceHanSansCN-Medium, SourceHanSansCN;
          font-weight: 500;
          color: #ffffff;
          line-height: 27px;
          opacity: 0.7;
        }
      }
    }
    .line {
      width: 1px;
      height: 52px;
      margin: 0 20px;
      background: linear-gradient(
        180deg,
        rgba(9, 217, 242, 0) 0%,
        #09d7f0 51%,
        rgba(9, 214, 239, 0) 100%
      );
    }
  }
  .chart-wrap {
    height: 232px;
    margin-left: 40px;
  }
}
</style>